package com.easemob.chat;

import android.text.TextUtils;
import com.easemob.chat.core.a;
import com.easemob.chat.core.e;
import com.easemob.util.EMLog;
import org.jivesoftware.smack.PacketListener;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.PacketExtension;

class RecvAckListener
  implements PacketListener
{
  private static final String TAG = "acklistener";

  public void processPacket(Packet paramPacket)
  {
    Message localMessage = (Message)paramPacket;
    EMLog.d("acklistener", localMessage.toXML());
    ChatListener.ackMessage(localMessage);
    if (processClientAckMessage(localMessage))
      return;
    PacketExtension localPacketExtension = localMessage.getExtension("urn:xmpp:receipts");
    if ((localPacketExtension != null) && (localPacketExtension.getElementName().equals("received")))
    {
      String str1 = localMessage.getBody();
      EMMessage localEMMessage = EMChatManager.getInstance().getMessage(str1);
      if ((localEMMessage != null) && ((localPacketExtension instanceof a)))
      {
        String str2 = ((a)localPacketExtension).a();
        if (!TextUtils.isEmpty(str2))
        {
          EMLog.d("acklistener", " found returned global server msg id : " + str2);
          EMChatManager.getInstance().replaceMessageId(str1, str2);
        }
      }
      EMLog.d("acklistener", "received server ack for msg:" + str1);
      EMSendMessageRunnable.notifySendLock(str1);
    }
  }

  private synchronized boolean processClientAckMessage(Message paramMessage)
  {
    PacketExtension localPacketExtension = paramMessage.getExtension("urn:xmpp:receipts");
    if (localPacketExtension == null)
      return false;
    String str = localPacketExtension.getElementName();
    if (str.equals("acked"))
    {
      if (!EMChatManager.getInstance().getChatOptions().getRequireAck())
      {
        EMLog.d("acklistener", "msg read ack is not enabled. skip ack msg received");
        return true;
      }
      EMLog.d("acklistener", "received message read ack for msg id:" + paramMessage.getBody());
      onReadAckReceived(paramMessage);
      return true;
    }
    if (str.equals("delivery"))
    {
      if (!EMChatManager.getInstance().getChatOptions().getRequireDeliveryAck())
      {
        EMLog.d("acklistener", "msg delivery ack is not enabled. skip ack msg received");
        return true;
      }
      EMLog.d("acklistener", "received message delivered ack for msg id:" + paramMessage.getBody());
      onDeliveryAckReceived(paramMessage);
      return true;
    }
    return false;
  }

  private void onReadAckReceived(Message paramMessage)
  {
    String str1 = paramMessage.getBody();
    EMMessage localEMMessage = EMChatManager.getInstance().getMessage(str1);
    if (localEMMessage == null)
      localEMMessage = e.a().c(str1);
    if (localEMMessage != null)
    {
      String str2 = EMContactManager.getUserNameFromEid(paramMessage.getFrom());
      localEMMessage.isAcked = true;
      e.a().f(str1, true);
      EMChatManager.getInstance().notifiyReadAckMessage(str2, str1);
    }
  }

  private void onDeliveryAckReceived(Message paramMessage)
  {
    String str1 = paramMessage.getBody();
    EMMessage localEMMessage = EMChatManager.getInstance().getMessage(str1);
    if (localEMMessage == null)
      localEMMessage = e.a().c(str1);
    if (localEMMessage != null)
    {
      String str2 = EMContactManager.getUserNameFromEid(paramMessage.getFrom());
      localEMMessage.isDelivered = true;
      e.a().h(str1, true);
      EMChatManager.getInstance().notifyDeliveryAckMessage(str2, str1);
    }
  }
}

/* Location:           D:\hygieia\userclient\common\libs\easemobchat_2.1.8.jar
 * Qualified Name:     com.easemob.chat.RecvAckListener
 * JD-Core Version:    0.6.1
 */